using System.Collections.Generic;

namespace ColladaDotNet.OpenTKMapping
{
	public class BindMaterial : DocumentLibraryElement<bind_material>
	{
		List<MaterialInstace> materialInstancies = new List<MaterialInstace>();
		internal override void Load(bind_material colladaData)
		{
			base.Load(colladaData);

			if (colladaData.technique_common != null)
				foreach (var instance_material1 in colladaData.technique_common)
				{
					materialInstancies.Add(Document.CreateElement<MaterialInstace>(instance_material1));
				}
		}

		public Material Bind(string material)
		{
			foreach (var c in materialInstancies)
			{
				if (c.Symbol == material)
				{
					var target = c.Target;
					if (target != null)
						target.Bind();
					return target;
				}
			}
			return null;
		}

		
	}
}